cars data

Scatterplot of cars data

Scatterplot of cars data


I will work with R’s internal dataset on cars: cars. There are two variables in the dataset, speed [speed] and distance [dist] this is what they look like.

We require two things:

  1. A claim based on target/hypothesized value
    • Alternative two-sided: \(\mu = target\) vs. \(\mu \neq target\)
    • Alternative greater: \(\mu \leq target\) vs. \(\mu > target\)
    • Alternative lesser: \(\mu \geq target\) vs. \(\mu < target\)
  2. A confidence level that is a threshold in probability for rendering a true/false answer.

Hypothesis Testing and \(t\)

I will work with the speed variable. Let me consider two distinct hypotheses though this is not entirely proper in the sense that any given application of hypothesis testing should have a clear hypothesis about the variable of interest rather than waffling amongst two as I will. I do so only for illustrative purposes. To begin, I need to specify both the hypothesis and the confidence level that I intend to use to evaluate it.

The \(t\) equation is given by:

\[t=\frac{\overline{x} - \mu}{\frac{s}{\sqrt{n}}}\]

One further algebraic manipulation before starting. Let’s solve for \(\overline{x}\).

\[\mu + t\left(\frac{s}{\sqrt{n}}\right)=\overline{x}\]

This fully defines the parts we require and the core problem

Details of the Data

  Mean       SD        SE  N
1 15.4 5.287644 0.7477858 50

\[t = \frac{15.4 - 17}{\frac{s}{\sqrt{n}}} = \frac{-1.6}{0.7478}=-2.14\]

Case 1: A Two-sided Alternative


Critical Values
P(-1.677 < X < 1.677)     = 0.9
1 - P(-1.677 < X < 1.677) = 0.1

Result
P(X < -2.14) = 0.019
P(X > 2.14) = 0.019
P(-2.14 < X < 2.14)     = 0.963
1 - P(-2.14 < X < 2.14) = 0.037

Knowing only the sample size, 50, is sufficient to determine what \(t\) must be to reject a mean of 17 in favor of the alternative that the true mean is not 17. With 0.9 probability, this implies two boundaries; either the true mean is smaller than 17, with 0.05 probability spanning 0 to 0.05 and it is bigger than 17 with 0.05 probability spanning 0.95 to 1 so that the interior range represents 0.9 probability as required.

Case 2: A Lesser Alternative


Critical Values
P(X < -1.299) = 0.1
P(X > -1.299) = 0.9

Result
P(X < -2.14) = 0.019
P(X > -2.14) = 0.981

Knowing only the sample size, 50, is sufficient to determine what \(t\) must be to reject a mean of 17 or greater in favor of the alternative that the true mean is less than 17. With 0.9 probability, either the true mean is smaller than 17, with 0.1 probability or it is 17 or bigger with 0.9 probability as required.

Case 3: A Greater Alternative


Critical Values
P(X < -1.299) = 0.1
P(X > -1.299) = 0.9

Result
P(X < -2.14) = 0.019
P(X > -2.14) = 0.981

Knowing only the sample size, 50, is sufficient to determine what \(t\) must be to reject a mean of 17 or greater in favor of the alternative that the true mean is less than 17. With 0.9 probability, either the true mean is smaller than 17, with 0.1 probability or it is 17 or bigger with 0.9 probability as required.

t.test

Alternative: Two-sided


    One Sample t-test

data:  cars$speed
t = -2.1397, df = 49, p-value = 0.03739
alternative hypothesis: true mean is not equal to 17
95 percent confidence interval:
 13.89727 16.90273
sample estimates:
mean of x 
     15.4 

Alternative: Less


    One Sample t-test

data:  cars$speed
t = -2.1397, df = 49, p-value = 0.01869
alternative hypothesis: true mean is less than 17
95 percent confidence interval:
    -Inf 16.6537
sample estimates:
mean of x 
     15.4 

Alternative: Greater


    One Sample t-test

data:  cars$speed
t = -2.1397, df = 49, p-value = 0.9813
alternative hypothesis: true mean is greater than 17
95 percent confidence interval:
 14.1463     Inf
sample estimates:
mean of x 
     15.4